
package 
{
	import flash.display.*;
	import flash.events.*;
	import flash.utils.*;
	
	
	
	public class CareerPath extends Sprite
	{
		public var arrayJob:Array;
		public var arrayStep:Array;
		
		private var stepColor:uint;
		
		public function CareerPath(profile:Object, axis:Axis)
		{
			this.visible = false;  // keep invisible at the beginning
			
			
			stepColor = Math.ceil(256*256*256*Math.random());
			
			arrayJob = new Array();
			arrayStep = new Array();
			
			if (arrayJob.length - 1 != arrayStep.length) {
				// TODO panic and exit, or alarm?
			}
	
			// push jobs and steps into array
			var i:int = 0;
			for (i = 0; i < profile.job.length(); i++) {
				arrayJob.push(new Job(profile.job[i]));
			}
			for (i = 0; i < profile.step.length(); i++) {
				arrayStep.push(new Step(profile.step[i], stepColor));
			}
			
			// layout a career path by connecting jobs and steps
			for (i = 0; i < arrayJob.length; i++) {
				// layout a job
				arrayJob[i].setXY(axis.getXY(arrayJob[i]));
				
				this.addChild(arrayJob[i]);
			}
			
			for (i = 0; i < arrayStep.length; i++) {
				// layout a step be connecting two jobs
				arrayStep[i].setXY(arrayJob[i].getXY(), arrayJob[i + 1].getXY());
				
				this.addChild(arrayStep[i]);
			}
			
			this.addEventListener(MouseEvent.CLICK, onClick);
		}
		
		private function onClick(e:MouseEvent):void {
			this.dispatchEvent(new Event("PATH_SELECTED", true));
		}
	}
}